// 并查集模版(洛谷)
// 本实现用递归函数实现路径压缩，而且省掉了小挂大的优化，一般情况下可以省略
// 测试链接 : https://www.luogu.com.cn/problem/P3367
// 提交以下所有代码，可以直接通过

#include <cstdio>

const int MAXN = 10001;

int father[MAXN];

int n, m;

void Build()
{
    for(int i = 0; i <= n; ++i) father[i] = i;
}

int Find(int i)
{
    if(i != father[i])
    {
        father[i] = Find(father[i]);
    }
    return father[i];
    // 像下面这样写也是可以的
    // return i == father[i] ? i : father[i] = Find(father[i]);
}

bool isSameSet(int x, int y)
{
    return Find(x) == Find(y);
}

void Union(int x, int y)
{
    father[Find(x)] = Find(y);
}

int main()
{
    scanf("%d%d", &n, &m);
    Build();
    for(int i = 0; i < m; ++i)
    {
        int opt, x, y;
        scanf("%d%d%d", &opt, &x, &y);
        if(opt == 2)
        {
            if(isSameSet(x, y)) printf("Y\n");
            else printf("N\n");
        }
        else
            Union(x, y);
    }

    return 0;
}